package nil.ed.simulator.request.repo;

import lombok.Getter;
import lombok.Setter;
import nil.ed.simulator.request.biz.qq.scheduler.QqLoginScheduleUnit;
import nil.ed.simulator.request.common.QQItem;
import nil.ed.simulator.request.parser.IParser;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @author lidelin.
 */
public class QQRepo {

    public final Object LOCK = new Object();

    @Getter
    private List<QQItem> qqList;

    @Setter
    @Getter
    private List<QqLoginScheduleUnit> finished;

    @Setter
    @Getter
    private List<QqLoginScheduleUnit> allUnits;

    public boolean isFinish() {
        return allUnits != null && allUnits.size() != 0 && allUnits.size() <= finished.size();
    }


    public void load(String file, IParser parser) throws IOException {
        String text = String.join("\n", IOUtils.readLines(new FileInputStream(new File(file)), StandardCharsets.UTF_8));
        qqList = parser.parse(text);
    }

}
